﻿using AutoMapper;
using B.S.DataBase.MyProject.Domain.ArrivalCheck;
using B.S.DataBase.MyProject.ErrorCode;
using B.S.DataBase.MyProject.Infrastructure.Interface;
using MediatR;
using T.E.ERP.Read.API.Applicantions.Command.CheckCommand;

namespace T.E.ERP.Read.API.Applicantions.CommandHandler.CheckCommandHandler
{
    public class GetCheckRecordListCommandHandler : IRequestHandler<GetCheckRecordListCommand, APIResult<List<CheckRecord>>>
    {
        private readonly IMapper mapper;
        private readonly IBaseRepository<CheckRecord> checkRecordBiz;


        public GetCheckRecordListCommandHandler(IMapper mapper, IBaseRepository<CheckRecord> checkRecordBiz)
        {
            this.mapper = mapper;
            this.checkRecordBiz = checkRecordBiz;
        }

        public Task<APIResult<List<CheckRecord>>> Handle(GetCheckRecordListCommand request, CancellationToken cancellationToken)
        {
            APIResult<List<CheckRecord>> result = new APIResult<List<CheckRecord>>();
            var checkRecordList = checkRecordBiz.Quary(x => x.PurchaseInRepository_ID == request.PurchaseInRepository_ID).Result;
            result.Count = checkRecordList.Count();
            result.data = checkRecordList.Skip((request.pageIndex - 1) * request.pageSize).Take(request.pageSize).ToList();
            result.Msg = APIEnum.成功.ToString();
            result.Code = APIEnum.成功;
            return Task.FromResult(result);
        }
    }
}
